<template>
  <router-view />
</template>

<script setup>
// 使用Vue Router中的功能
import { onMounted, onUnmounted } from 'vue';
import { useRouter } from 'vue-router';
import { useUserStore } from './stores/user';

const router = useRouter();
const userStore = useUserStore();

// 监听浏览器页面刷新和关闭
const handleBeforeUnload = () => {
  // 可以在这里添加离开前的提示或数据保存逻辑
  // 这里不添加任何确认提示，纯粹作为钩子示例
};

onMounted(() => {
  window.addEventListener('beforeunload', handleBeforeUnload);
  
  // 检查页面加载时的登录状态
  if (userStore.isLoggedIn) {
    console.log('用户已登录，角色:', userStore.isMerchant ? '商家' : '顾客');
  } else {
    console.log('用户未登录');
  }
});

onUnmounted(() => {
  window.removeEventListener('beforeunload', handleBeforeUnload);
});
</script>

<style>
html, body, #app {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

#app {
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

* {
  box-sizing: border-box;
}

/* 主题颜色 */
:root {
  --primary-color-user: #FF6B98;
  --primary-color-merchant: #67C23A;
  --background-user: #f9f0f2;
  --background-merchant: #f5f7fa;
}

/* 页面切换动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 常用工具类 */
.text-center {
  text-align: center;
}

.text-primary-user {
  color: var(--primary-color-user);
}

.text-primary-merchant {
  color: var(--primary-color-merchant);
}

.mb-10 {
  margin-bottom: 10px;
}

.mb-20 {
  margin-bottom: 20px;
}

.mt-10 {
  margin-top: 10px;
}

.mt-20 {
  margin-top: 20px;
}
</style>
